<?php
namespace app\common\model;
use think\Request;

/**
 * 店员模型
 */
class ShopClerk extends BaseModel
{
    protected $name = 'shop_clerk';

	/**
     * 关联门店表
     */
    public function shop()
    {
        return $this->belongsTo('Shop');
    }
	
    /**
     * 身份
     */
    public function getStatusAttr($value)
    {
        $status = [10 => '店员', 20 => '店长', 30 => '配送'];
        return ['text' => $status[$value], 'value' => $value];
    }

    /**
     * 获取列表
     */
    public function getList()
    {
        // 排序规则
        $sort = [];
        $sort = ['shop_clerk_id' => 'desc'];
        // 执行查询
        $list = $this->with(['shop'])
            ->order($sort)
            ->paginate(15, false, ['query' => Request::instance()->request()]);
        return $list;
    }
	
	/**
	* API 获取列表
	*/
	public function getLists($shop_id=0,$wxapp_id = null){
		if (is_null($wxapp_id)) {
            $wxapp_id = self::$wxapp_id;
        }
		$where['wxapp_id'] = $wxapp_id;
		$shop_id > 0 && $where['shop_id'] = $shop_id;
		return $this->useGlobalScope(false)->where($where)->order('shop_clerk_id','desc')->select();
	}

    /**
     * 获取详情
     */
    public static function detail($where)
    {
        return self::get($where, ['shop']);
    }
}
